package com.common.util;

import java.io.File;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
import java.util.Scanner;

public class Text {

	public static final String DBDRIVER = "com.mysql.jdbc.Driver";
	public static final String DBURL = "jdbc:mysql://localhost:3306/search?useUnicode=true&characterEncoding=utf8";
	public static final String DBUSER = "root";
	public static final String DBPASSWORD = "123";

	public static void main(String[] args) throws Exception {
		Connection conn = null;
		Class.forName(DBDRIVER);
		conn = DriverManager.getConnection(DBURL, DBUSER, DBPASSWORD);
		Statement stmt = conn.createStatement();
        int id=1028;
        int parentId =1028;
		Scanner reader = new Scanner(new File("d:\\txt.txt"));
		while (reader.hasNextLine()) {
			String tmep = reader.nextLine();
				
				if(tmep.indexOf("：")>-1){
					System.out.println("大类:"+tmep.replace("：", "")+"---id:"+id);
					String dl= tmep.replace("：", "");
					String sql="insert into category_info(ID,Name,status,sort_Top,parent_Id,is_Last,sys_Type) values('"+id+"','"+dl+"','1','"+id+"','1','0','1')";// sys_Type：1是安卓 2是苹果 parent_Id：1是安卓 2是苹果is_Last:是否有子节点 1是有 1是没有
					stmt.executeUpdate(sql);
					parentId = id;
					id++;
				}else{
					String[] x = tmep.split("、");
					for (int j = 0; j < x.length; j++) {
						String type_d = x[j];
						System.out.println("小类："+type_d+"---id:"+id);
						String sql="insert into category_info(id,Name,status,sort_Top,parent_Id,is_Last,sys_Type) values('"+id+"','"+type_d+"','1','"+id+"','"+parentId+"','1','1')";// sys_Type：1是安卓 2是苹果 parent_Id：是父类的ID
						stmt.executeUpdate(sql);
						id++;
					}
			}
		}
		stmt.close();
		conn.close();
	}

}
